package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/6 22:05
 */
public class 二叉树的最小深度111 {
    public int minDepth(TreeNode root) {
        return recur(root);
    }

    public int recur(TreeNode node) {
        if (node == null) {
            return 0;
        }
        if (node.left != null && node.right != null) {
            int leftVal = recur(node.left);
            int rightVal = recur(node.right);
            return Math.min(leftVal, rightVal) + 1;
        } else if (node.left == null) {
            return recur(node.right) + 1;
        } else {
            return recur(node.left) + 1;
        }
    }
}
